package rabbit.flt.test.common.spi;

import rabbit.flt.common.Metrics;
import rabbit.flt.common.MetricsDataHandler;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ConsoleMetricsDataHandler implements MetricsDataHandler {

    private static Map<String, MetricsDataHandler> handlerMap = new ConcurrentHashMap<>();

    @Override
    public void handle(Metrics metrics) {
        handlerMap.forEach((name, handler) -> handler.handle(metrics));
    }

    @Override
    public int getPriority() {
        return 1000;
    }

    public static void addHandler(String name, MetricsDataHandler handler) {
        handlerMap.put(name, handler);
    }

    public static void clearHandlers() {
        handlerMap.clear();
    }
}
